package flc.ast.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;

import com.blankj.utilcode.util.ToastUtils;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.databinding.ActivityChangePwdBinding;
import flc.ast.utils.Content;
import flc.ast.view.PasscodeView;
import stark.common.basic.utils.SPUtil;

public class ChangePwdActivity extends BaseAc<ActivityChangePwdBinding> {


    @Override
    protected int onCreate() {
        return R.layout.activity_change_pwd;
    }

    @Override
    protected void initView() {
        mDataBinding.ivChangePwdBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        mDataBinding.passcodeView.setListener(new PasscodeView.PasscodeViewListener() {
            @Override
            public void onFail() {
                mDataBinding.passcodeView.getWrongStatusColor();
            }

            @Override
            public void onSuccess(String number) {
                SPUtil.putString(mContext, Content.myPassword, number);
                ToastUtils.showShort(getString(R.string.change_pwd_suc));
                finish();
            }
        });
        mDataBinding.tvInputAnswerNext.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()){
            case R.id.tvInputAnswerNext:
                String answer = mDataBinding.etInputAnswerText.getText().toString().trim();
                if (answer.isEmpty()) return;
                String myAnswer=SPUtil.getString(mContext,Content.myAnswer,"");
                if (answer.equals(myAnswer)){
                    mDataBinding.llInputSecure.setVisibility(View.GONE);
                    mDataBinding.llChangePwd.setVisibility(View.VISIBLE);
                }else{
                    ToastUtils.showShort(getString(R.string.answer_is_error));
                }
                break;
        }
    }

    @Override
    protected void initData() {
        String problem=SPUtil.getString(mContext,Content.myProblem,"");
        mDataBinding.tvAnswerProblem.setText(problem);
    }
}